<?php
	//
	// copie un repertoire et son contenu recursivement
	//
	function copy_dir($source, $dest, $overwrite = false){
		if($handle = opendir($source)){
			while(false !== ($file = readdir($handle))){
				if($file != '.' && $file != '..'){
					$src_path = $source.DIRECTORY_SEPARATOR.$file;
					$dest_path = $dest.DIRECTORY_SEPARATOR.$file;
					if(is_file($src_path)){
						if(!is_file($dest_path) || $overwrite){
							if(!@copy($src_path, $dest_path)){
								echo '<font color="red">File ('.$src_path.') <br/>';
								echo 'could not be copied into '.$dest_path.'<br/>';
								echo 'likely a permissions problem.</font>';
							}
						}
					}elseif(is_dir($src_path)){
						if(!is_dir($dest_path)){
							// make subdirectory before subdirectory is copied
							mkdir($dest_path);
						}
						copy_dir($src_path, $dest_path, $overwrite);
					}
				}
			}
			closedir($handle);
		}
	}
	//
?>